package com.baizan.daka.ui.adapter


import android.widget.ImageView
import android.widget.TextView
import com.baizan.daka.mvp.model.bean.TaskInfoBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.dianzan.daka.R

class TaskAdapter : BaseQuickAdapter<TaskInfoBean, BaseViewHolder>(R.layout.item_task) {

    var listener: OnItemClickListener?  = null

    override fun setOnItemClickListener(listener: OnItemClickListener?) {
        this.listener = listener

    }
    fun setReceived(index:Int){
        data[index].received =1
        data[index].completeNumber ++
        notifyItemChanged(index)
    }

    override fun convert(helper: BaseViewHolder, item: TaskInfoBean) {
        helper.setText(R.id.user_phone_tv, "需方：${item?.createUser}")
            .setText(R.id.task_msg_tv, "要求：${item?.taskTypeName}")
            .setText(R.id.remain_tv, "剩余：${item?.totalNumber - item?.completeNumber}")
            .setText(R.id.price_tv, "¥${item.taskPrice}")
            .setText(R.id.task_No_tv, "编号：${item.id}")

        if (item.received == 1) {
            helper.setText(R.id.task_submit_tv, "已领取")
            helper.setEnabled(R.id.task_submit_tv, false)
        } else {
            helper.setText(R.id.task_submit_tv, "领取任务")
            helper.setEnabled(R.id.task_submit_tv, true)
        }
        helper.getView<TextView>(R.id.task_submit_tv)
            .setOnClickListener{
                listener?.let {
                    it.onItemClick(this,helper.getView<TextView>(R.id.task_submit_tv),helper.adapterPosition)
                }
            }
        when (item.taskClass) {
            1 ->
                helper.getView<ImageView>(R.id.task_icon_iv).setImageResource(R.mipmap.icon_douyin)
            2 ->
                helper.getView<ImageView>(R.id.task_icon_iv)
                    .setImageResource(R.mipmap.icon_kuanshou)
            0 ->{

                helper.getView<ImageView>(R.id.task_icon_iv)
                    .setImageResource(R.mipmap.icon_pengyouquan)
            }
        }
        var taskLevel = helper.getView<TextView>(R.id.task_level_tv)
        when (item.taskLevel) {
            1 -> {
                taskLevel.text = "初级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_1)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_1)
                    , null, null, null
                )
            }
            2 -> {
                taskLevel.text = "中级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_2)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_2)
                    , null, null, null
                )
            }
            3 -> {
                taskLevel.text = "高级任务"
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_3)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_3)
                    , null, null, null
                )
            }
            4->{
                taskLevel.text = "至尊任务"
                taskLevel.setBackgroundResource(R.drawable.shape_task_level_4)
                taskLevel.setCompoundDrawablesWithIntrinsicBounds(
                    mContext.getResources().getDrawable(R.mipmap.icon_item_task_4)
                    , null, null, null
                )
            }


        }
    }


}